package org.example;

public class Girlfriend {
    private int age;
    private String name;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age<18||age>40){
           throw new AgeOutOfBoundsException(age+"年龄错误");
        }
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name.length()<2||name.length()>16){
           throw new NameFormatException(name+"格式错误");
        }
        this.name = name;
    }

   public Girlfriend() {
   }

    public Girlfriend(int age, String name) {
        this.age = age;
        this.name = name;
    }
    @Override
    public String toString() {
        return "Girlfriend{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
